<?php
header("content-type:text/html;charset=utf-8");

session_start();

if(isset($_SESSION["u_user"]))
{
	$name = $_SESSION["u_user"];
    if(isset($_POST["submit"]))
	{
		if($_POST['username']=='admin' || $_POST['username']==''){
	        echo '<script>alert("非法用户名");location.href="add_user.php"</script>';
	    }if($_POST['username']==''|| $_POST['password']=='' || $_POST['depart']=='' ){
	        echo '<script>alert("添加信息不能为空！");location.href="add_user.php"</script>';
	    }
		else{
		    include_once('classes/user/user.class.php');
		    $user = new user();
            $result = $user->select_user_exist($_POST['username'],'u_user');
		    if(!$result) {
				if($user->add_user($_POST['username'],$_POST['password'],$_POST['depart'])){
		            echo '<script>alert("添加成功");location.href="users.php"</script>';
		        }else{
			         echo '<script>alert("添加失败");location.href="add_user.php"</script>';
		        }
			}else{
			     echo '<script>alert("用户已存在");location.href="add_user.php"</script>';
			}
		}
	}
	else
	{
        include_once('classes/depart/depart.class.php');
        $depart = new depart();
        $info = $depart->get_all_depart();

?>
	<!DOCTYPE html>
		<html lang="en">
		<head>
			<meta charset="utf-8">
			<title>管理</title>
			<meta name="description" content="mobile first, app, web app, responsive, admin dashboard, flat, flat ui">
			<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
			<link rel="stylesheet" href="caches/css/bootstrap.css">
			<link rel="stylesheet" href="caches/css/font-awesome.min.css">
			<link rel="stylesheet" href="caches/css/style.css">
			<link rel="stylesheet" href="caches/css/plugin.css">
			<link rel="stylesheet" href="caches/css/landing.css">
			<!--[if lt IE 9]>
			<script src="caches/js/ie/respond.min.js"></script>
			<script src="caches/js/ie/html5.js"></script>
			<![endif]-->
		</head>
		<body>
		<!-- header -->
		<header id="header" class="navbar">
			<ul class="nav navbar-nav navbar-avatar pull-right">
				<li class="dropdown">
					<a href="#" class="dropdown-toggle" data-toggle="dropdown">
						<span class="hidden-sm-only"></span>
						<span class="thumb-small avatar inline"><img src="caches/images/avatar.jpg" alt="" class="img-circle"></span>
						<b class="caret hidden-sm-only"></b>
					</a>
					<ul class="dropdown-menu">
						<li class="icon-gear"><span class="text"><a href="#">设置</a></span></li>
						<li class="divider"></li>
						<li class="icon-signout"><span class="text"><a href="quit.php">注销</a></span></li>
					</ul>
				</li>
			</ul>
			<a class="navbar-brand" href="#">管理</a>
			<button type="button" class="btn btn-link pull-left nav-toggle hidden-lg" data-toggle="class:slide-nav slide-nav-left" data-target="body">
				<i class="icon-reorder icon-xlarge text-default"></i>
			</button>
			<ul class="nav navbar-nav hidden-sm">
				<li class="dropdown shift" data-toggle="shift:appendTo" data-target=".nav-primary .nav">
					<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="icon-cog icon-xlarge visible-sm visible-sm-inline"></i>设置<b class="caret hidden-sm-only"></b></a>
					<ul class="dropdown-menu">
						<li>
							<a href="#" data-toggle="class:navbar-fixed" data-target='body'>
								<span class="text-active">自动</span>
								<span class="text">固定</span>
							</a>
						</li>
						<li class="visible-lg">
							<a href="#" data-toggle="class:nav-vertical" data-target="#nav">
								<span class="text-active">垂直</span>
								<span class="text">水平</span>
							</a>
						</li>
						<li class="divider hidden-sm"></li>
						<li class="dropdown-header">颜色</li>
						<li>
							<a href="#" data-toggle="class:bg bg-black" data-target='.navbar'>上：
								<span class="text-active">白色</span>
								<span class="text">黑色</span>
							</a>
						</li>
						<li>
							<a href="#" data-toggle="class:bg-light" data-target='#nav'>左：
								<span class="text-active">暗</span>
								<span class="text">亮</span>
							</a>
						</li>
					</ul>
				</li>
			</ul>
		</header>
		<nav id="nav" class="nav-primary visible-lg nav-vertical">
			<ul class="nav" data-spy="affix" data-offset-top="50">
				<li class="dropdown-submenu">
					<a href="#"><i class="icon-group icon-xlarge"></i>部门</a>
					<ul class="dropdown-menu">
						<li><a href="add_depart.php">新增</a></li>
						<li><a href="department.php">编辑</a></li>
					</ul>
				</li>
				<li class="dropdown-submenu">
					<a href="#"><i class="icon-male icon-xlarge"></i>员工</a>
					<ul class="dropdown-menu">
						<li><a href="add_user.php">新增</a></li>
						<li><a href="users.php">编辑</a></li>
					</ul>
				</li>
				<li><a href="admin.php"><i class="icon-edit icon-xlarge"></i>加班信息</a></li>
				<li class="dropdown-submenu">
					<a href="#"><i class="icon-signout icon-xlarge"></i>其他</a>
					<ul class="dropdown-menu">
						<li><a href="quit.php">注销</a></li>
					</ul>
				</li>
			</ul>
		</nav>			
<!-- 内容区域 -->
		<section id="content">
			<section class="main padder">
				<div class="clearfix">
					<h4><i class="icon-male"></i>员工信息</h4>
				</div>
				<div class="row">
					<div class="panel">
						<div class="clearfix">
						<form class="form-horizontal" method="post" action="add_user.php">
							<div class="form-group">
								<label for="username" class="col-sm-2 control-label">姓名</label>
								<div class="col-sm-2">
									 <input type="text" class="form-control" id="username"  name="username">
								</div>
							</div>
							<div class="form-group">
								<label for="password" class="col-sm-2 control-label">密码</label>
								<div class="col-sm-2">
									<input type="text" class="form-control" id="password"  name="password">
								</div>
							</div>
							<div class="form-group">
								<label  for="depart" class="col-sm-2 control-label">所属部门</label>
								<div class="col-sm-2">
									<select class="form-control" id="depart" name="depart" type="text" placeholder="depart">
										<?php for($i=0;$i<count($info);$i++){?>
										<option value="<?php echo $info[$i]['d_name']?>"><?php echo $info[$i]['d_name']?></option>
										<?php }?>
									</select>
								</div>
							 </div>
							 <div class="form-group">
								  <div class="col-sm-2 control-label">
									  <input type="submit" id="submit" name="submit" class="btn btn-default" value="提交">
								  </div>
							</div>
						</form>
						</div>
					 </div>
				</div>
			</section>
		</section>
        <footer id="footer">
            <div class="text-center padder clearfix">
                <p>
                    <small>&copy;山东舜网传媒股份有限公司</small><br><br>
                </p>
            </div>
        </footer>
        <!-- / footer -->
        <script src="caches/js/jquery.min.js"></script>
        <!-- Bootstrap -->
        <script src="caches/js/bootstrap.js"></script>
        <!-- app -->
        <script src="caches/js/app.js"></script>
        <script src="caches/js/app.plugin.js"></script>
        <script src="caches/js/app.data.js"></script>
        <!-- fuelux -->
        <script src="caches/js/fuelux/fuelux.js"></script>
        <!-- datepicker -->
        <script src="caches/js/datepicker/bootstrap-datepicker.js"></script>
        <!-- slider -->
        <script src="caches/js/slider/bootstrap-slider.js"></script>
        <!-- file input -->
        <script src="caches/js/file-input/bootstrap.file-input.js"></script>
        <!-- combodate -->
        <script src="caches/js/combodate/moment.min.js"></script>
        <script src="caches/js/combodate/combodate.js"></script>
        <!-- parsley -->
        <script src="caches/js/parsley/parsley.min.js"></script>
        
</body>

</html>
<?php 
	}
	}

else{
	echo '<script>alert("请先登录");location.href="login1.php";</script>';
}






?>